From f64eff9355cb63c56f38c551a9247f8e9f248790 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 22 Sep 2022 15:58:45 -0400 Subject: [PATCH] test: Added --test-with-git-config option Sponsored-by: Dartmouth College's DANDI project --- CHANGELOG | 1 + Test.hs | 20 +++++++++++++++---- Test/Framework.hs | 15 ++++++++++---- Types/Test.hs | 2 ++ doc/git-annex-test.mdwn | 14 +++++++++++++ .../specify_gitconfig_for_test_suite.mdwn | 3 +++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e74887764c..172f0c14ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -31,6 +31,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium * Improved handling of --time-limit when combined with -J * Fix updating git index file after getting an unlocked file when annex.stalldetection is set. + * test: Added --test-with-git-config option. -- Joey Hess Mon, 29 Aug 2022 15:03:04 -0400 diff --git a/Test.hs b/Test.hs index 5ec5d8d1de..78eeef882e 100644 --- a/Test.hs +++ b/Test.hs @@ -1,6 +1,6 @@ {- git-annex test suite - - - Copyright 2010-2021 Joey Hess + - Copyright 2010-2022 oey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -13,12 +13,12 @@ import Types.Test import Types.RepoVersion import Types.Concurrency import Test.Framework -import Options.Applicative.Types import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck -import Options.Applicative (switch, long, short, help, internal, maybeReader, option) +import Options.Applicative.Types +import Options.Applicative (switch, long, short, help, internal, maybeReader, option, metavar) import qualified Data.Map as M import qualified Data.ByteString.Lazy.UTF8 as BU8 @@ -92,7 +92,7 @@ import qualified Utility.Gpg optParser :: Parser TestOptions optParser = TestOptions - <$> snd (tastyParser (tests 1 False True (TestOptions mempty False False Nothing mempty))) + <$> snd (tastyParser (tests 1 False True (TestOptions mempty False False Nothing mempty mempty))) <*> switch ( long "keep-failures" <> help "preserve repositories on test failure" @@ -106,7 +106,19 @@ optParser = TestOptions <> short 'J' <> help "number of concurrent jobs" )) + <*> many (option (maybeReader parseconfigvalue) + ( long "test-git-config" + <> help "run tests with a git config set" + <> metavar "NAME=VALUE" + )) <*> cmdParams "non-options are for internal use only" + where + parseconfigvalue s = case break (== '=') s of + (_, []) -> Nothing + (k, v) -> Just + ( Git.Types.ConfigKey (encodeBS k) + , Git.Types.ConfigValue (encodeBS (drop 1 v)) + ) runner :: TestOptions -> IO () runner opts = parallelTestRunner opts tests diff --git a/Test/Framework.hs b/Test/Framework.hs index 2d8e0c6e2e..a4f24066ed 100644 --- a/Test/Framework.hs +++ b/Test/Framework.hs @@ -169,7 +169,7 @@ withtmpclonerepo' cfg a = do case r of Right () -> return () Left e -> do - whenM (keepFailures <$> getTestMode) $ + whenM (keepFailuresOption . testOptions <$> getTestMode) $ putStrLn $ "** Preserving repo for failure analysis in " ++ clone throwM e @@ -255,6 +255,13 @@ configrepo dir = indir dir $ do -- tell git-annex to not annex the ingitfile git "config" ["annex.largefiles", "exclude=" ++ ingitfile] "git config annex.largefiles" + -- set any additional git configs the user wants to test with + gc <- testGitConfig . testOptions <$> getTestMode + forM_ gc $ \case + (Git.Types.ConfigKey k, Git.Types.ConfigValue v) -> + git "config" [decodeBS k, decodeBS v] + "git config from test options" + (Git.Types.ConfigKey _, Git.Types.NoConfigValue) -> noop ensuredir :: FilePath -> IO () ensuredir d = do @@ -483,15 +490,15 @@ data TestMode = TestMode { unlockedFiles :: Bool , adjustedUnlockedBranch :: Bool , annexVersion :: Types.RepoVersion.RepoVersion - , keepFailures :: Bool - } deriving (Show) + , testOptions :: TestOptions + } testMode :: TestOptions -> Types.RepoVersion.RepoVersion -> TestMode testMode opts v = TestMode { unlockedFiles = False , adjustedUnlockedBranch = False , annexVersion = v - , keepFailures = keepFailuresOption opts + , testOptions = opts } hasUnlockedFiles :: TestMode -> Bool diff --git a/Types/Test.hs b/Types/Test.hs index b41864d256..9d0af77208 100644 --- a/Types/Test.hs +++ b/Types/Test.hs @@ -11,12 +11,14 @@ import Test.Tasty.Options import Types.Concurrency import Types.Command +import Git.Types data TestOptions = TestOptions { tastyOptionSet :: OptionSet , keepFailuresOption :: Bool , fakeSsh :: Bool , concurrentJobs :: Maybe Concurrency + , testGitConfig :: [(ConfigKey, ConfigValue)] , internalData :: CmdParams } diff --git a/doc/git-annex-test.mdwn b/doc/git-annex-test.mdwn index 31c77b0cb2..17923cc026 100644 --- a/doc/git-annex-test.mdwn +++ b/doc/git-annex-test.mdwn @@ -30,6 +30,20 @@ framework. Pass --help for details about those. When there are test failures, leave the `.t` directory populated with repositories that demonstate the failures, for later analysis. +* `--test-git-config name=value` + + The test suite prevents git from reading any git configuration files. + Usually it is a good idea to run the test suite with a standard + git configuration. However, this option can be useful to see what + effect a git configuration setting has on the test suite. + + Some configuration settings will break the test suite, in ways that are + due to a bug in git-annex. But it is possible that changing a + configuration can find a legitimate bug in git-annex. + + One valid use of this is to change a git configuration to a value that + is planned to be the new default in a future version of git. + # SEE ALSO [[git-annex]](1) diff --git a/doc/todo/specify_gitconfig_for_test_suite.mdwn b/doc/todo/specify_gitconfig_for_test_suite.mdwn index 891fb9c66e..78cf7d78f5 100644 --- a/doc/todo/specify_gitconfig_for_test_suite.mdwn +++ b/doc/todo/specify_gitconfig_for_test_suite.mdwn @@ -1,5 +1,8 @@ `git-annex test` prevents ~/.gitconfig or /etc/gitconfig from being read. +The `-c` option also doesn't propagate into the test suite. It would sometimes be useful to test git-annex with a given git config set. Although some might break the test suite, others might expose actual bugs in git-annex. --[[Joey]] + +> Added "--test-git-config" option, [[done]] --[[Joey]] -- 2.30.2